// package-activity/pages/stats/index.js
import { TARGET_TYPE } from '../../../constants/common';
import { ManageTargetExchangeMixins } from '../../../behaviors/page';
import { showLoading, hideLoading } from '../../../common/env';
import { statsIncomeActivity, statsSpokesmanRankActivity } from '../../../api/brd';
let brandId, activityId;

Page({
    mixins: [ManageTargetExchangeMixins],
    data: {
        tabsData: [
            { value: 'all', text: '全部数据' },
            { value: 'self', text: '自卖数据' },
            { value: 'help', text: '帮卖数据' },
        ],
        statsInfo: {},
        spokesmanRankList: [],
    },
    async onLoad(options) {
        brandId = options.brandId;
        activityId = options.activityId;
        const { showDistributeStats } = options;
        this.setData({ showDistributeStats });
        showLoading('加载中...');
        await this._handleExchange(TARGET_TYPE.brand, brandId);
        await this._handleGetDetail();
        await this._handleGetSpokesmanRank();
        hideLoading();
    },
    async _handleGetDetail() {
        const statsInfo = await statsIncomeActivity({ activityId });
        this.setData({ statsInfo });
        console.log('Brand Activity Stats => 活动数据统计=>收入', statsInfo);
    },
    async _handleGetSpokesmanRank() {
        const spokesmanRankList = await statsSpokesmanRankActivity({ activityId });
        this.setData({ spokesmanRankList });
        console.log('Brand Activity Stats => 活动数据统计=>代言人排名', spokesmanRankList);
    },
    handleTabChange(e) {
        const { key } = e.detail;
    },
})
